package com.weiwei.diancan.utils;

import android.app.Activity;

import com.weiwei.diancan.Contant.Config;
import com.weiwei.diancan.bean.LoginBean;
import com.weiwei.diancan.cache.CacheConfig;

import org.greenrobot.eventbus.EventBus;

import weiwei.com.weiweilibrary.views.ToastUtil;

/**
 * Created by BMW on 2016/12/30.
 */
public class HttpUtils {

    public static void check(LoginBean loginBean, Activity activity,OnSuccessListener listener){
        if(loginBean.getIs_success().equals("1")){
            LoginBean login = CacheConfig.getInst().getLogin();

            ToastUtil.showToast(activity,loginBean.getReason());
            loginBean.setShop_token(CacheConfig.getInst().getToken(activity));
            loginBean.setName5(login.getName5());
            CacheConfig.getInst().putData(loginBean);
            EventBus.getDefault().post(Config.LOGIN_SUCCESS);
            listener.onSuccess(loginBean);
        }else if(loginBean.getIs_success().equals("-1")){
            android.os.Process.killProcess(android.os.Process.myPid());
            CacheConfig.getInst().clearToken(activity);
        }else if(loginBean.getIs_success().equals("-2")){
            android.os.Process.killProcess(android.os.Process.myPid());
            CacheConfig.getInst().clearWaterToken(activity);
        }else{
            ToastUtil.showToast(activity,loginBean.getReason());
        }
    }
}
